home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************************
- CWASTEDlgText.c
-
- A class with some of the functionality of CDialogText, but using CWASTEText
-
- ******************************************************************************/
-
- #ifdef TCL_PCH
- #include <TCLHeaders>
- #endif
-
- #include "CWASTEDlgText.h"
- #include "CDialog.h"
- #include <CPaneBorder.h>
- #include "CBartender.h"
- #include "Constants.h"
-
- #define kBorderAmount 2 // white space between border and text of edit field
-
- extern CBartender *gBartender;
- extern CBureaucrat *gGopher; // First in line to get commands
-
- static pascal void WEPostUpdate(WEHandle hWE, long fixLength, long inputAreaStart,
- long inputAreaEnd, long pinRangeStart, long pinRangeEnd);
-
- extern CWASTEText *gWASTEText; /* Current WASTEText object */
-
- TCL_DEFINE_CLASS_D1(CWASTEDlgText, CWASTEText);
-
-
- /********************************************************\
- CWASTEDlgText - default constructor
- \********************************************************/
-
- CWASTEDlgText::CWASTEDlgText()
- {
- TCL_END_CONSTRUCTOR
- }
-
-
- /********************************************************\
- CWASTEDlgText - constructor
- \********************************************************/
-
- CWASTEDlgText::CWASTEDlgText(
- CView *anEnclosure,
- CView *aSupervisor,
- short aWidth,
- short aHeight,
- short aHEncl,
- short aVEncl,
- SizingOption aHSizing,
- SizingOption aVSizing,
- short aLineWidth,
- Boolean aScrollHoriz,
- Boolean aIsRequired,
- long aMaxValidLength,
- Boolean aValidateOnResign)
-
- : CWASTEText(anEnclosure, aSupervisor,
- aWidth, aHeight, aHEncl, aVEncl,
- aHSizing, aVSizing, aLineWidth, aScrollHoriz)
- {
-
- IWASTEDlgTextX();
- TCL_END_CONSTRUCTOR
- }
-
-
- /********************************************************\
- ~CWASTEDlgText - destructor
- \********************************************************/
-
- CWASTEDlgText::~CWASTEDlgText()
- {
- TCL_START_DESTRUCTOR
- }
-
-
- /********************************************************\
- IWASTEDlgText - initializer, if used with default
- constructor
- \********************************************************/
-
- void CWASTEDlgText::IWASTEDlgText(CView *anEnclosure, CView *aSupervisor,
- short aWidth, short aHeight,
- short aHEncl, short aVEncl,
- SizingOption aHSizing, SizingOption aVSizing,
- short aLineWidth)
- {
-
- CWASTEText::IWASTEText(anEnclosure, aSupervisor,
- aWidth, aHeight, aHEncl, aVEncl,
- aHSizing, aVSizing, aLineWidth);
-
- IWASTEDlgTextX();
- }
-
-
- /********************************************************\
- IViewTemp - construct from View resource
- \********************************************************/
-
- void CWASTEDlgText::IViewTemp(CView *anEnclosure, CBureaucrat *aSupervisor,
- Ptr viewData)
- {
- CWASTEText::IViewTemp(anEnclosure, aSupervisor, viewData);
-
- IWASTEDlgTextX();
- }
-
-
- /********************************************************\
- IWASTEDlgTextX - common initialization
- \********************************************************/
-
- void CWASTEDlgText::IWASTEDlgTextX()
- {
- WETSMPostUpdateProcPtr postProc;
-
- MakeBorder();
- SetWholeLines(FALSE);
-
- // set postupdate routine to WEPostUpdate
- postProc = &WEPostUpdate;
- WESetInfo(weTSMPostUpdate, (Ptr)&postProc, macWE);
- }
-
- /********************************************************\
- WEPostUpdate -- broadcast a dialog text changed message
- \********************************************************/
-
- static pascal void WEPostUpdate(WEHandle hWE, long fixLength, long inputAreaStart,
- long inputAreaEnd, long pinRangeStart, long pinRangeEnd)
- {
- short ID;
- GrafPtr curPort;
- if (gWASTEText != NULL)
- {
- GetPort(&curPort);
- ID = gWASTEText->ID;
- gWASTEText->BroadcastChange(dialogTextChanged, &ID);
- SetPort(curPort);
- gWASTEText->Prepare();
- }
- }
-
-
- /********************************************************\
- MakeBorder - put a border around the text
- \********************************************************/
-
- void CWASTEDlgText::MakeBorder()
- {
- Rect margin;
- CPaneBorder *border;
-
- border = TCL_NEW(CPaneBorder,());
- border->IPaneBorder(kBorderFrame);
- SetRect(&margin, -kBorderAmount, -kBorderAmount, kBorderAmount, kBorderAmount);
- border->SetMargin(&margin);
- SetBorder(border);
- }
-
- /********************************************************\
- DoKey - handle Tab and Return
- \********************************************************/
-
- void CWASTEDlgText::DoKeyDown(char theChar, Byte keyCode, EventRecord *macEvent)
- {
- Boolean pass = TRUE;
- short ID;
-
- switch (theChar)
- {
- case '\t':
- case '\r':
- case kEnterKey:
- pass = FALSE;
- break;
-
- case kEscapeOrClear:
- if (keyCode == KeyEscape) pass = FALSE;
- break;
- }
- if (pass)
- {
- CWASTEText::DoKeyDown(theChar, keyCode, macEvent);
-
- if (itsTypingTask && itsTypingTask->CanStillType())
- {
- ID = this->ID;
- BroadcastChange(dialogTextChanged, &ID);
- }
- }
- else
- itsSupervisor->DoKeyDown(theChar, keyCode, macEvent);
- }
-
- /********************************************************\
- GetTextString - return the text as a pascal string
- \********************************************************/
-
- void CWASTEDlgText::GetTextString(StringPtr aString)
- {
- short length = Min(GetLength(), 255);
-
- StopInlineSession();
- BlockMove(*GetTextHandle(), &aString[1], length);
- aString[0] = length;
- }
-
- /********************************************************\
- PerformEditCommand - handle cut, copy, paste, and clear
- -- check for text changed
- \********************************************************/
-
- void CWASTEDlgText::PerformEditCommand(long theCommand)
- {
- short ID;
-
- CWASTEText::PerformEditCommand(theCommand);
-
- switch( theCommand)
- {
- case cmdCut:
- case cmdPaste:
- case cmdClear:
- ID = this->ID;
- BroadcastChange(dialogTextChanged, &ID);
- break;
-
- default:
- break;
- }
-
- }
-
-
-